<template>
  <div class="container">
    <div class="top">
      <div class="top-header">
        <span class="left">列表</span>
        <div class="right">
          <el-button v-if="type === 'audit'" type="primary" class="add" @click="strategyAudit">确定</el-button>
          <el-button @click="$router.back()" class="refresh">取消</el-button>
        </div>
      </div>
      <div class="top-content">
        <div class="content">
          <div class="basic-info">
            <div class="title">
              <div class="icon"></div>
              <div class="desc">基本信息</div>
            </div>
            <div class="basic">
              <el-avatar shape="circle" :size="50" fit="contain" :src="strategyDetail.createUserInfo.avatar || require('@/assets/images/profile.png')"></el-avatar>
              <div class="info">
                <div class="name">{{strategyDetail.createBy}}</div>
                <div class="time">{{strategyDetail.createTime}}</div>
              </div>
            </div>
          </div>
          <div class="question-info">
            <div class="question">{{strategyDetail.title}}</div>
            <div class="answer">{{strategyDetail.content}}</div>
          </div>
          <div v-if="strategyDetail.img" class="img-list">
            <div class="item">
              <el-avatar shape="square" :size="80" fit="contain" :src="strategyDetail.img"></el-avatar>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div class="bottom" v-if="(type === 'detail' && auditStatus !== '0') || type === 'audit'">
      <div class="bottom-content">
        <div class="title">
          <div class="icon"></div>
          <div class="desc">审核结果</div>
        </div>
        <div class="formItem">
          <div class="left">
            <div class="label">审核结果<span>*</span></div>
            <div class="content">
              <div class="choose_item" @click="chooseAuditStatus('1')">
                <img v-if="auditStatus === '1'" src="@/assets/images/selected_circle.png" alt="">
                <img v-else src="@/assets/images/un_selected_circle.png" alt="">
                <span>通过</span>
              </div>
              <div class="choose_item" @click="chooseAuditStatus('2')">
                <img v-if="auditStatus === '2'" src="@/assets/images/selected_circle.png" alt="">
                <img v-else src="@/assets/images/un_selected_circle.png" alt="">
                <span>不通过</span>
              </div>
            </div>
          </div>
        </div>
        <div class="formItem" v-if="auditStatus === '2'">
          <div class="left">
            <div class="label">不通过原因<span>*</span></div>
            <el-input :readonly="type === 'detail'" style="width: 398px" v-model="reason"></el-input>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import {strategyAudit, strategyDetail} from "@/api/form/strategy";

export default {
  mounted() {
    this.type = this.$route.query.type
    this.getStrategyDetail(this.$route.query.id)
  },
  data() {
    return {
      strategyDetail: {},
      auditStatus: '',
      reason: '',
      type: '' // detail/audit
    }
  },
  methods: {
    async getStrategyDetail(id) {
      const { code, data, msg } = await strategyDetail(id)
      if (code === 200) {
        this.strategyDetail = data
        this.auditStatus = this.strategyDetail.auditStatus
        this.reason = this.strategyDetail.auditReason
      } else {
        this.$message({message: msg, type: 'error'})
      }
    },
    chooseAuditStatus(auditStatus) {
      if (this.type === 'detail') return
      this.auditStatus = auditStatus
    },
    async strategyAudit() {
      if (this.auditStatus === '0') {
        this.$message({message: '请选择审核结果', type: 'warning'})
        return
      }
      if (this.auditStatus === '2' && !this.reason) {
        this.$message({message: '请输入不通过原因', type: 'warning'})
        return
      }
      const { code, msg } = await strategyAudit({
        auditReason: this.reason,
        auditStatus: this.auditStatus,
        id: this.$route.query.id
      })
      if (code === 200) {
        this.$message({message: '审核成功', type: 'success'})
        this.$router.back()
      } else {
        this.$message({message: msg})
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.container {
  width: 100%;
  height: 100%;
  background: var(--theme_bg_color);
  .top {
    .top-header {
      padding: 21px 24px;
      background: #fff;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #E4E7ED;
      .left {
        font-size: 16px;
        font-weight: 400;
        color: #111111;
      }
      .right {
        display: flex;
        align-items: center;
        justify-content: flex-start;
        .add {
          background: #3370FF;
          border: none;
        }
        .export {
          background: #79CF1C;
          border: none;
        }
      }
    }
    .top-content {
      background: #fff;
      padding: 16px 0;
      display: flex;
      justify-content: center;
      .content {
        width: 70%;
        display: flex;
        flex-direction: column;
        .basic-info {
          .basic {
            height: 50px;
            display: flex;
            align-items: center;
            .info {
              height: 100%;
              display: flex;
              flex-direction: column;
              justify-content: space-between;
              margin-left: 10px;

              font-size: 14px;
              font-weight: 400;
              color: #1F2329;
            }
          }
        }
        .question-info {
          margin-top: 30px;
          .question {
            font-size: 20px;
            font-weight: 400;
            color: #1F2329;
            margin-bottom: 10px;
          }
          .info {
            font-size: 16px;
            font-weight: 400;
            color: #1F2329;
          }
        }
        .img-list {
          display: flex;
          margin-top: 20px;
          .item {
            margin-right: 10px;
          }
        }
      }
    }
  }
  .bottom {
    margin-top: 20px;
    background: #fff;
    padding: 16px 0;
    display: flex;
    justify-content: center;
    .bottom-content {
      width: 70%;
    }
  }
  .title {
    display: flex;
    align-items: center;
    margin-bottom: 25px;
    .icon {
      width: 4px;
      height: 16px;
      background: #3370FF;
      margin-right: 10px;
    }
    .desc {
      font-size: 16px;
      font-weight: 400;
      color: #333333;
    }
  }
  .formItem {
    width: 100%;
    display: flex;
    margin-bottom: 24px;
    .left,
    .right {
      height: 100%;
      flex: 1;
      display: flex;
      flex-direction: column;
    }
    .left {
      margin-right: 12px;
    }
    .right {
      margin-left: 12px;
      img {
        width: 88px;
        height: 88px;
        border-radius: 6px 6px 6px 6px;
        border: 1px solid #d0d3d6;
      }
    }
    .label {
      font-size: 14px;
      font-weight: 400;
      color: #333333;
      margin-bottom: 20px;
      span {
        color: #f54a45;
      }
    }
    .content {
      display: flex;
      align-items: center;
      .choose_item {
        margin-right: 30px;
        display: flex;
        align-items: center;
        img {
          width: 16px;
          height: 16px;
          margin-right: 10px;
        }
        span {
          font-size: 14px;
          font-weight: 400;
          color: #999999;
        }
      }
    }
  }
}
</style>
